<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>你好</title>
    <style>
        * {
            box-sizing: border-box;
        }
        html, body {
            width: 100% !important;
            height: 100% !important;
            margin: 0 !important;
            padding: 0 !important;
            overflow: hidden !important;
            background-color: #000;
        }
        
        #contentFrame {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            margin: 0 !important;
            padding: 0 !important;
            border: none !important;
            outline: none !important;
            box-shadow: none !important;
            background-color: #000;
            overflow: hidden;
        }
        
        .error-container {
            display: flex;
            justify-content: center;
            align-items: center;
            width: 100%;
            height: 100%;
            background: #000;
        }
        
        .error-content {
            color: #fff;
            text-align: center;
            max-width: 90%;
            padding: 20px;
            border-radius: 8px;
            background: rgba(50, 50, 50, 0.8);
            font-family: Arial, sans-serif;
        }
        
        .error-detail {
            font-size: 14px;
            margin-top: 15px;
            color: #aaa;
            word-break: break-all;
        }
        
        @media screen and (max-width: 600px) {
            html, body {
                -webkit-touch-callout: none;
                -webkit-user-select: none;
                -ms-user-select: none;
                user-select: none;
            }
        }
    </style>
    <script>
        // 转义HTML特殊字符的函数
        function escapeHtml(unsafe) {
            if (!unsafe) return '';
            return unsafe.toString()
                .replace(/&/g, "&amp;")
                .replace(/</g, "&lt;")
                .replace(/>/g, "&gt;")
                .replace(/"/g, "&quot;")
                .replace(/'/g, "&#039;");
        }

        // 初始化函数
        function init() {
            // 获取URL参数
            const params = new URLSearchParams(window.location.search);
            const pathParam = params.get('p');
            
            let targetUrl = 'about:blank';
            let errorMessage = null;
            
            // 处理路径参数
            if (pathParam) {
                try {
                    // 编码参数并构建URL
                    const encodedParam = encodeURIComponent(pathParam);
                    const fullUrl = `https://vip.fmkefu.com/c/${encodedParam}`;
                    
                    // URL格式验证
                    if (fullUrl.match(/^https?:\/\/[^\s/$.?#].[^\s]*$/i)) {
                        targetUrl = fullUrl;
                    } else {
                        throw new Error('无效的固定链接格式');
                    }
                } catch (e) {
                    errorMessage = '链接生成错误: ' + e.message;
                    console.error('[ERROR]', errorMessage, '输入:', pathParam);
                }
            } else {
                errorMessage = '缺少路径参数 "p"';
                console.error('[ERROR]', errorMessage);
            }
            
            // 显示错误信息或设置iframe
            if (errorMessage) {
                const errorContainer = document.getElementById('errorContainer');
                errorContainer.style.display = 'flex';
                document.getElementById('errorText').innerHTML = escapeHtml(errorMessage);
                document.getElementById('errorDetail').textContent = pathParam ? 
                    `参数值: ${escapeHtml(pathParam)}` : 
                    '请提供有效的URL参数';
            } else {
                const frame = document.getElementById('contentFrame');
                frame.src = targetUrl;
                frame.style.display = 'block';
                initFrame();
            }
        }

        // 初始化iframe
        function initFrame() {
            const frame = document.getElementById('contentFrame');
            if (!frame) return;
            
            // 设置大小
            frame.width = window.innerWidth;
            frame.height = window.innerHeight;
            
            // 加载事件
            frame.addEventListener('load', function() {
                console.log('Frame content loaded');
            });
            
            // 错误事件
            frame.addEventListener('error', function(err) {
                console.error('Frame load error', err);
                document.getElementById('errorContainer').style.display = 'flex';
                document.getElementById('errorText').textContent = '页面加载失败';
                document.getElementById('errorDetail').textContent = '目标网站阻止了加载请求';
            });
        }

        // 窗口大小调整
        window.addEventListener('resize', function() {
            const frame = document.getElementById('contentFrame');
            if (frame) {
                frame.style.width = window.innerWidth + 'px';
                frame.style.height = window.innerHeight + 'px';
            }
        });

        // 防止多点触控缩放
        document.addEventListener('touchstart', function(e) {
            if (e.touches.length > 1) {
                e.preventDefault();
            }
        }, { passive: false });

        document.addEventListener('gesturestart', function(e) {
            e.preventDefault();
        });

        // 页面加载完成后初始化
        window.addEventListener('DOMContentLoaded', function() {
            init();
            console.log('Host page loaded');
            
            // 3秒后检查加载状态
            setTimeout(function() {
                const frame = document.getElementById('contentFrame');
                if (frame && frame.style.display === 'block' && 
                   (!frame.contentDocument || frame.contentDocument.readyState !== 'complete')) {
                    console.warn('Frame not loaded after timeout');
                    const warning = document.createElement('div');
                    warning.textContent = '...';
                    warning.style.position = 'fixed';
                    warning.style.bottom = '10px';
                    warning.style.left = '10px';
                    warning.style.color = '#fff';
                    warning.style.background = 'rgba(0,0,0,0.7)';
                    warning.style.padding = '5px 10px';
                    warning.style.borderRadius = '4px';
                    warning.style.fontSize = '12px';
                    document.body.appendChild(warning);
                }
            }, 3000);
        });
    </script>
</head>
<body>
    <!-- 错误信息容器 (默认隐藏) -->
    <div id="errorContainer" class="error-container" style="display: none;">
        <div class="error-content">
            <h3>配置错误</h3>
            <p id="errorText"></p>
            <div id="errorDetail" class="error-detail"></div>
        </div>
    </div>
    
    <!-- 内容框架 (默认隐藏) -->
    <iframe 
        id="contentFrame"
        frameborder="0"
        scrolling="yes"
        allow="fullscreen"
        sandbox="allow-same-origin allow-scripts allow-popups allow-forms allow-modals allow-top-navigation"
        allowfullscreen
        style="display:none;"></iframe>
</body>
</html>